//
//  CollectViewController.m
//  LiangYa_BObject
//
//  Created by dllo on 15/11/2.
//  Copyright © 2015年 YuHao. All rights reserved.
//

#import "CollectViewController.h"
#import "AppDelegate.h"
#import "CollectCollectionViewCell.h"
#import "CollectHandler.h"
#import "ClassCol.h"
#import "IdeaCol.h"
#import "ClassColPushViewController.h"
#import "IdeaDetallViewController.h"
#import "TeachingWebViewController.h"
#import "TeachingData.h"
#import "LikeViewController.h"
#import "MainCol.h"
#import "TeachCol.h"

@interface CollectViewController ()<UICollectionViewDataSource, UICollectionViewDelegate, UIScrollViewDelegate>

@property (nonatomic, strong) UIButton *backB;
@property (nonatomic, strong) UIButton *editB;
@property (nonatomic, strong) UIButton *deleteB;
@property (nonatomic, strong) UIButton *mainBtn;
@property (nonatomic, strong) UIButton *classBtn;
@property (nonatomic, strong) UIButton *teachBtn;
@property (nonatomic, strong) UIButton *ideaBtn;
@property (nonatomic, strong) UIScrollView *scrollV;
@property (nonatomic, strong) NSArray *mainArr;
@property (nonatomic, strong) NSArray *classArr;
@property (nonatomic, strong) NSArray *teachArr;
@property (nonatomic, strong) NSArray *ideaArr;
@property (nonatomic, strong) UIView *moveV;
@property (nonatomic, strong) NSMutableArray *deleteArr;
@property (nonatomic, strong) NSMutableArray *deletecellArr;

@end

@implementation CollectViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"我的收藏";
    
    CollectHandler *col = [CollectHandler instandDefault];
    // 分类
    NSFetchRequest *classReq = [NSFetchRequest fetchRequestWithEntityName:@"ClassCol"];
    self.classArr = [col.managedObjectContext executeFetchRequest:classReq error:nil];
    // 主页
    NSFetchRequest *mainReq = [NSFetchRequest fetchRequestWithEntityName:@"MainCol"];
    self.mainArr = [col.managedObjectContext executeFetchRequest:mainReq error:nil];
    // 创意
    NSFetchRequest *teachReq = [NSFetchRequest fetchRequestWithEntityName:@"TeachCol"];
    self.teachArr = [col.managedObjectContext executeFetchRequest:teachReq error:nil];
    // 推荐
    NSFetchRequest *ideaReq = [NSFetchRequest fetchRequestWithEntityName:@"IdeaCol"];
    self.ideaArr = [col.managedObjectContext executeFetchRequest:ideaReq error:nil];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.mainBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    _mainBtn.frame = CGRectMake(ScreenWidth / 4 * 0, 20, ScreenWidth / 4, 40);
    [_mainBtn setTitle:@"主页" forState:UIControlStateNormal];
    [_mainBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    _mainBtn.tag = 0;
    [self.view addSubview:_mainBtn];
    [_mainBtn addTarget:self action:@selector(moveScrollVAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.classBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    _classBtn.frame = CGRectMake(ScreenWidth / 4 * 1, 20, ScreenWidth / 4, 40);
    [_classBtn setTitle:@"分类" forState:UIControlStateNormal];
    [_classBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _classBtn.tag = ScreenWidth;
    [self.view addSubview:_classBtn];
    [_classBtn addTarget:self action:@selector(moveScrollVAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.teachBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    _teachBtn.frame = CGRectMake(ScreenWidth / 4 * 2, 20, ScreenWidth / 4, 40);
    [_teachBtn setTitle:@"创意" forState:UIControlStateNormal];
    [_teachBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    _teachBtn.tag = ScreenWidth * 2;
    [self.view addSubview:_teachBtn];
    [_teachBtn addTarget:self action:@selector(moveScrollVAction:) forControlEvents:UIControlEventTouchUpInside];
    
    self.ideaBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    _ideaBtn.frame = CGRectMake(ScreenWidth / 4 * 3, 20, ScreenWidth / 4, 40);
    [_ideaBtn setTitle:@"推荐" forState:UIControlStateNormal];
    [_ideaBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.ideaBtn.tag = ScreenWidth * 3;
    [self.view addSubview:_ideaBtn];
    [_ideaBtn addTarget:self action:@selector(moveScrollVAction:) forControlEvents:UIControlEventTouchUpInside];
    if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
        [_classBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_teachBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [_ideaBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    }
    
    self.moveV = [[UIView alloc] initWithFrame:CGRectMake(0, 58, ScreenWidth / 4, 2)];
    _moveV.backgroundColor = [UIColor redColor];
    [self.view addSubview:_moveV];
    
    self.scrollV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 60, ScreenWidth, Screenheight - 60)];
    _scrollV.contentSize = CGSizeMake(ScreenWidth * 4, Screenheight - 60);
    [self.view addSubview:_scrollV];
    _scrollV.delegate = self;
    _scrollV.pagingEnabled = YES;
    _scrollV.backgroundColor = [UIColor clearColor];
    _scrollV.showsHorizontalScrollIndicator = NO;
    _scrollV.tag = 1000;
    for (NSInteger i = 0; i < 4; i ++) {
        
        UICollectionViewFlowLayout *flowL = [[UICollectionViewFlowLayout alloc] init];
        flowL.itemSize = CGSizeMake((ScreenWidth - 15) / 2, (ScreenWidth - 15) / 2);
        flowL.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
        flowL.minimumInteritemSpacing = 5;
        flowL.minimumLineSpacing = 5;
        
        UICollectionView *collectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(ScreenWidth * i, 0, ScreenWidth, Screenheight - 60) collectionViewLayout:flowL];
        collectionV.backgroundColor = [UIColor clearColor];
        collectionV.delegate = self;
        collectionV.dataSource = self;
        collectionV.tag = i + 100;
        [collectionV registerClass:[CollectCollectionViewCell class] forCellWithReuseIdentifier:@"collectcell"];
//        [collectionV registerClass:[CollectCollectionViewCell class] forCellWithReuseIdentifier:[NSString stringWithFormat:@"collectcell_%ld", i]];
        [self.scrollV addSubview:collectionV];
    }
    
    
    // 返回按钮
    self.backB = [UIButton buttonWithType:UIButtonTypeSystem];
    _backB.backgroundColor = [UIColor colorWithRed:1.000 green:0.000 blue:0.139 alpha:1.000];
    _backB.frame = CGRectMake(20, Screenheight - 60, 40, 40);
    _backB.layer.cornerRadius = 20;
    UIImage *backI = [[UIImage imageNamed:@"picture1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [_backB setImage:backI forState:UIControlStateNormal];
    [_backB setImageEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
    [_backB addTarget:self action:@selector(backAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_backB];
    
    // 编辑按钮
    self.editB = [UIButton buttonWithType:UIButtonTypeSystem];
    _editB.frame = CGRectMake(ScreenWidth - 60, Screenheight - 60, 40, 40);
    _editB.layer.cornerRadius = 20;
    _editB.backgroundColor = [UIColor colorWithRed:1.000 green:0.000 blue:0.139 alpha:1.000];
    [_editB setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [_editB setTitle:@"编辑" forState:UIControlStateNormal];
    [_editB addTarget:self action:@selector(editAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_editB];
    
    // 删除按钮
    self.deleteB = [UIButton buttonWithType:UIButtonTypeSystem];
    _deleteB.backgroundColor = [UIColor colorWithRed:1.000 green:0.000 blue:0.139 alpha:1.000];
    _deleteB.frame = CGRectMake(0, Screenheight, ScreenWidth, 50);
    UIImage *deleteI = [[UIImage imageNamed:@"shanchu"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [_deleteB setImage:deleteI forState:UIControlStateNormal];
    [_deleteB addTarget:self action:@selector(deletAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_deleteB];
    
}


- (void)moveScrollVAction:(UIButton *)btn
{
    [self.scrollV setContentOffset:CGPointMake(btn.tag, 0) animated:YES];
    [UIView animateWithDuration:0.5 animations:^{
        self.moveV.frame = CGRectMake(btn.tag / 4, 58, ScreenWidth / 4, 2);
    } completion:^(BOOL finished) {
        self.backB.hidden = NO;
        self.editB.hidden = NO;
    }];
    NSArray *btnArr = @[_mainBtn, _classBtn, _teachBtn, _ideaBtn];
    for (UIButton *tempBtn in btnArr) {
        if (tempBtn.tag == btn.tag) {
            [tempBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        }else{
            if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
                [tempBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            }else{
                [tempBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            }
        }
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    self.editB.hidden = YES;
    self.backB.hidden = YES;
    if (scrollView.tag == 1000) {
//        NSLog(@"%f", scrollView.contentOffset.x);
        self.moveV.frame = CGRectMake(scrollView.contentOffset.x / 4, 58, ScreenWidth / 4, 2);
    }
}

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    
    self.editB.hidden = NO;
    self.backB.hidden = NO;
    if (scrollView.tag == 1000) {
        
        NSInteger page = (NSInteger)scrollView.contentOffset.x / ScreenWidth;
        switch (page) {
            case 0:
                [self.mainBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
                if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
                    [self.classBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    [self.teachBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    [self.ideaBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                }else{
                    [self.classBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    [self.teachBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    [self.ideaBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                }
                break;
            case 1:
                [self.classBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
                if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
                    [self.mainBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    [self.teachBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    [self.ideaBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                }else{
                    [self.mainBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    [self.teachBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    [self.ideaBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                }
                break;
            case 2:
                [self.teachBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
                if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
                    [self.mainBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    [self.classBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    [self.ideaBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                }else{
                    [self.mainBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    [self.classBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    [self.ideaBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                }
                break;
            case 3:
                [self.ideaBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
                if ([[NSUserDefaults standardUserDefaults]boolForKey:@"nightstyle"]) {
                    [self.mainBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    [self.classBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                    [self.teachBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                }else{
                    [self.mainBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    [self.classBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                    [self.teachBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
                }
                break;
                
            default:
                break;
        }
    }
}

// 点击方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    if (self.scrollV.scrollEnabled == NO) {
        
        if (collectionView.tag == 100) {
            CollectCollectionViewCell *cell = (CollectCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
            MainCol *selectC = [self.mainArr objectAtIndex:indexPath.item];
            if (cell.tagBtn.hidden == YES) {
                cell.tagBtn.hidden = NO;
                [self.deleteArr addObject:selectC];
                [self.deletecellArr addObject:cell];
            }else{
                cell.tagBtn.hidden = YES;
                [self.deleteArr removeObject:selectC];
                [self.deletecellArr removeObject:cell];
            }
        }else if (collectionView.tag == 101) {
            CollectCollectionViewCell *cell = (CollectCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
            ClassCol *selectC = [self.classArr objectAtIndex:indexPath.item];
            if (cell.tagBtn.hidden == YES) {
                cell.tagBtn.hidden = NO;
                [self.deleteArr addObject:selectC];
                [self.deletecellArr addObject:cell];
            }else{
                cell.tagBtn.hidden = YES;
                [self.deleteArr removeObject:selectC];
                [self.deletecellArr removeObject:cell];
            }
        }else if (collectionView.tag == 102) {
            CollectCollectionViewCell *cell = (CollectCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
            TeachCol *selectC = [self.teachArr objectAtIndex:indexPath.item];
            if (cell.tagBtn.hidden == YES) {
                cell.tagBtn.hidden = NO;
                [self.deleteArr addObject:selectC];
                [self.deletecellArr addObject:cell];
            }else{
                cell.tagBtn.hidden = YES;
                [self.deleteArr removeObject:selectC];
                [self.deletecellArr removeObject:cell];
            }
        }else if (collectionView.tag == 103){
            CollectCollectionViewCell *cell = (CollectCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
            IdeaCol *selectC = [self.ideaArr objectAtIndex:indexPath.item];
            if (cell.tagBtn.hidden == YES) {
                cell.tagBtn.hidden = NO;
                [self.deleteArr addObject:selectC];
                [self.deletecellArr addObject:cell];
            }else{
                cell.tagBtn.hidden = YES;
                [self.deleteArr removeObject:selectC];
                [self.deletecellArr removeObject:cell];
            }
        }
        
    }else{
        if (collectionView.tag == 100) {
            MainCol *mainCol = [self.mainArr objectAtIndex:indexPath.item];
            
            LikeViewController *likeVC = [[LikeViewController alloc] init];
            likeVC.str = mainCol.idNum;
            likeVC.str1 = mainCol.pic;
            [self presentViewController:likeVC animated:YES completion:^{
                
            }];
        }
    if (collectionView.tag == 101) {
        
        ClassCol *classCol = [self.classArr objectAtIndex:indexPath.item];
        
        ClassColPushViewController *classCPVC = [[ClassColPushViewController alloc] init];
        classCPVC.brandName = classCol.brandName;
        classCPVC.image = classCol.image;
        classCPVC.content = classCol.content;
        classCPVC.price = classCol.price;
        classCPVC.soldNum = classCol.soleNum;
        classCPVC.urlStr = classCol.buyUrl;
        [self presentViewController:classCPVC animated:YES completion:^{
            
        }];
    }
        if (collectionView.tag == 102) {
            
            TeachCol *teachCol = [self.teachArr objectAtIndex:indexPath.item];
            
            TeachingWebViewController *teachWVC = [[TeachingWebViewController alloc] init];
            teachWVC.teachingData = [[TeachingData alloc] init];
            teachWVC.teachingData.title = teachCol.title;
            teachWVC.teachingData.content_url = teachCol.content_url;
            teachWVC.isPresent = YES;
            [self presentViewController:teachWVC animated:YES completion:^{
                
            }];
        }
    if (collectionView.tag == 103) {
        IdeaDetallViewController *ideaVC = [[IdeaDetallViewController alloc] init];
        IdeaCol *ideaCol = [self.ideaArr objectAtIndex:indexPath.item];
        ideaVC.boo = NO;
        ideaVC.ideaData = [[IdeaData alloc] init];
        ideaVC.ideaData.albumName = ideaCol.albumName;
        ideaVC.ideaData.pic = ideaCol.pic;
        ideaVC.ideaData.albumLink = ideaCol.attribute;
        ideaVC.ideaData.detail = ideaCol.detail;
        [self presentViewController:ideaVC animated:YES completion:^{
            
        }];
    }
    }
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (collectionView.tag == 100) {
        return _mainArr.count;
    }else if (collectionView.tag == 101) {
        return _classArr.count;
    }else if (collectionView.tag == 102)
        return _teachArr.count;
    else{
        return _ideaArr.count;
    }
    
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    CollectCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectcell" forIndexPath:indexPath];
    
    UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(editAction:)];
    
    longPress.minimumPressDuration = 0.7;   //长按时间
    longPress.allowableMovement = 200;    //长按范围
    
    [cell addGestureRecognizer:longPress];
    
    if (collectionView.tag == 100) {
        
        MainCol *mainCol = [self.mainArr objectAtIndex:indexPath.item];
        [cell.imageV sd_setImageWithURL:[NSURL URLWithString:mainCol.pic]];
        cell.title.text = mainCol.name;
        return cell;
        
    }else if (collectionView.tag == 101) {
        
        ClassCol *classCol = [self.classArr objectAtIndex:indexPath.item];
        [cell.imageV sd_setImageWithURL:[NSURL URLWithString:classCol.image]];
        cell.title.text = classCol.content;
        return cell;
        
    }else if (collectionView.tag == 102) {
        
        TeachCol *teachCol = [self.teachArr objectAtIndex:indexPath.item];
        [cell.imageV sd_setImageWithURL:[NSURL URLWithString:teachCol.cover_image_url]];
        cell.title.text = teachCol.title;
        return cell;
        
    }else{
        
        IdeaCol *ideaCol = [self.ideaArr objectAtIndex:indexPath.item];
        [cell.imageV sd_setImageWithURL:[NSURL URLWithString:ideaCol.pic]];
        cell.title.text = ideaCol.albumName;
        return cell;
        
    }
    
}

- (void)deletAction:(UIButton *)btn
{
    self.scrollV.scrollEnabled = YES;
    [UIView animateWithDuration:0.5 animations:^{
        _backB.frame = CGRectMake(20, Screenheight - 60, 40, 40);
        _editB.frame = CGRectMake(ScreenWidth - 60, Screenheight - 60, 40, 40);
        _deleteB.frame = CGRectMake(0, Screenheight, ScreenWidth, 50);
    }];
    
    for (CollectCollectionViewCell *cell in self.deletecellArr) {
        cell.tagBtn.hidden = YES;
    }
    CollectHandler *col = [CollectHandler instandDefault];
    
    if (self.scrollV.contentOffset.x == 0) {
        for (MainCol *deletC in _deleteArr) {
            [col.managedObjectContext deleteObject:deletC];
        }
        [col saveContext];
        NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"MainCol"];
        self.mainArr = [col.managedObjectContext executeFetchRequest:request error:nil];
    }else if (self.scrollV.contentOffset.x == ScreenWidth) {
        
        for (ClassCol *deletC in _deleteArr) {
            [col.managedObjectContext deleteObject:deletC];
        }
        [col saveContext];
        NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"ClassCol"];
        self.classArr = [col.managedObjectContext executeFetchRequest:request error:nil];
    }else if (self.scrollV.contentOffset.x == ScreenWidth * 2) {
        for (TeachCol *deletC in _deleteArr) {
            [col.managedObjectContext deleteObject:deletC];
        }
        [col saveContext];
        NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"TeachCol"];
        self.teachArr = [col.managedObjectContext executeFetchRequest:request error:nil];
    }else {
        for (IdeaCol *deletC in _deleteArr) {
            [col.managedObjectContext deleteObject:deletC];
        }
        [col saveContext];
        NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"IdeaCol"];
        self.teachArr = [col.managedObjectContext executeFetchRequest:request error:nil];
    }
    
    for (NSInteger i = 100; i < 104; i ++) {
        UICollectionView *collectionV = (UICollectionView *)[self.view viewWithTag:i];
        [collectionV reloadData];
    };
    
}

- (void)editAction:(UIButton *)btn
{
    self.deletecellArr = [NSMutableArray array];
    self.deleteArr = [NSMutableArray array];
    self.scrollV.scrollEnabled = NO;
    [UIView animateWithDuration:0.5 animations:^{
        _backB.frame = CGRectMake(20, Screenheight, 40, 40);
        _editB.frame = CGRectMake(ScreenWidth - 60, Screenheight, 40, 40);
        _deleteB.frame = CGRectMake(0, Screenheight - 50, ScreenWidth, 50);
    }];
    
//    [[MarkButton appearance] setHidden:NO];
    
        UICollectionView *collectionV = (UICollectionView *)[self.view viewWithTag:(_scrollV.contentOffset.x / ScreenWidth + 100)];
        [collectionV reloadData];
    
}

- (void)backAction:(UIButton *)btn
{
    [self dismissViewControllerAnimated:YES completion:^{ 
//        AppDelegate *appD = (AppDelegate *)[[UIApplication sharedApplication] delegate];
//        
//        [appD.leftSlideVC closeLeftView];
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
